
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
-- Crea vista historia_clinica
-- drop view historia_clinica

CREATE VIEW [dbo].[historia_clinica] AS
SELECT	CASE a.Sexo
			WHEN 1 THEN 'M'
			WHEN 2 THEN 'F'
		END AS pers_sexo,
		a.Documento AS pers_documento,
		CASE h.GrupoYFactorSanguineo
			WHEN 1 THEN 1
			WHEN 2 THEN 1
			WHEN 3 THEN 2
			WHEN 4 THEN 2
			WHEN 5 THEN 3
			WHEN 6 THEN 3
			WHEN 7 THEN 4
			WHEN 8 THEN 4
		END AS hist_clin_factor_rh,
		CASE h.GrupoYFactorSanguineo
			WHEN 1 THEN 1
			WHEN 2 THEN 2
			WHEN 3 THEN 1
			WHEN 4 THEN 2
			WHEN 5 THEN 1
			WHEN 6 THEN 2
			WHEN 7 THEN 1
			WHEN 8 THEN 2
		END AS hist_clin_grupo_sanguineo,
		a.AptitudFisica AS hist_clin_discapacitado   
FROM	tb_HistoriaClinica h inner join tb_Agentes a ON (h.Agente = a.idAgente)
GO
